<template>
  <button @click="isShow = true">弹出弹窗</button>
  <teleport to="body">
    <div v-show="isShow" class="mask">
      <div class="dialog">
        <h3>弹窗</h3>
        <h4>内容</h4>
        <h4>内容</h4>
        <h4>内容</h4>
        <button @click="isShow=false">关闭弹窗</button>
      </div>
    </div>
  </teleport>
</template>

<script>
import {ref} from "vue";

export default {
  name: "Dialog",
  components: {},
  props: [],
  emits: [], // 用于注册VC的自定义事件，可不写，但会报警
  setup() {
    let isShow = ref(false);
    return {
      isShow,
    }
  },
}
</script>

<style scoped>
.dialog {
  height: 300px;
  width: 300px;
  background-color: green;
  text-align: center;
  position: relative;
  top: 50%;
  left: 50%;
  right: 50%;
  transform: translate(-50%, -50%);
}

.mask {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.5);
}
</style>